<ix-modal-header [requiredRoles]="requiredRoles" [title]="title" [loading]="isLoading"></ix-modal-header>
<mat-card>
  <mat-card-content>
    <form class="ix-form-container" [formGroup]="form" (submit)="onSubmit()">
      <div class="fieldsets">
        <ix-fieldset
          class="fieldset"
          [title]="helptext.transferTitle | translate"
        >
          @if (form.controls.description.enabled) {
            <ix-input
              formControlName="description"
              [label]="helptext.descriptionLabel | translate"
              [required]="true"
            ></ix-input>
          }
          @if (form.controls.direction.enabled) {
            <ix-select
              formControlName="direction"
              [label]="helptext.directionLabel | translate"
              [tooltip]="helptext.directionTooltip | translate"
              [required]="true"
              [options]="directionOptions$"
            ></ix-select>
          }
          @if (form.controls.transfer_mode.enabled) {
            <ix-select
              formControlName="transfer_mode"
              [label]="helptext.transferModeLabel | translate"
              [tooltip]="transferModeTooltip | translate"
              [required]="true"
              [options]="transferModeOptions$"
            ></ix-select>
          }
          <ix-transfer-mode-explanation
            [mode]="form.controls.transfer_mode.value"
          ></ix-transfer-mode-explanation>
          @if (form.controls.path_destination.enabled) {
            <ix-explorer
              formControlName="path_destination"
              [label]="helptext.pathLabel | translate"
              [tooltip]="helptext.pathTooltip | translate"
              [required]="true"
              [nodeProvider]="fileNodeProvider"
            ></ix-explorer>
          }
          @if (form.controls.path_source.enabled) {
            <ix-explorer
              formControlName="path_source"
              [label]="helptext.pathLabel | translate"
              [tooltip]="helptext.pathTooltip | translate"
              [required]="true"
              [multiple]="true"
              [nodeProvider]="fileNodeProvider"
            ></ix-explorer>
          }
        </ix-fieldset>

        <ix-fieldset
          class="fieldset"
          [title]="helptext.remoteTitle | translate"
        >
          <a
            ixTest="manage-credentials"
            (click)="goToManageCredentials()"
          >
            <div class="link">
              {{ 'Manage Credentials' | translate }}<ix-icon name="open_in_new"></ix-icon>
            </div>
          </a>
          @if (form.controls.credentials.enabled) {
            <ix-cloud-credentials-select
              formControlName="credentials"
              [label]="helptext.credentialLabel | translate"
              [tooltip]="helptext.credentialsTooltip | translate"
              [required]="true"
            ></ix-cloud-credentials-select>
          }
          @if (form.controls.bucket.enabled) {
            <ix-select
              formControlName="bucket"
              [label]="bucketPlaceholder | translate"
              [tooltip]="bucketTooltip | translate"
              [options]="bucketOptions$"
            ></ix-select>
          }
          @if (form.controls.bucket_input.enabled) {
            <ix-input
              formControlName="bucket_input"
              [label]="bucketInputPlaceholder | translate"
              [tooltip]="bucketInputTooltip | translate"
              [required]="true"
            ></ix-input>
          }
          @if (form.controls.folder_destination.enabled) {
            <ix-explorer
              formControlName="folder_destination"
              [rootNodes]="[slashRootNode]"
              [readonly]="!hasRequiredRoles()"
              [label]="helptext.folderLabel | translate"
              [tooltip]="helptext.folderTooltip | translate"
              [nodeProvider]="bucketNodeProvider"
            ></ix-explorer>
          }
          @if (form.controls.folder_source.enabled) {
            <ix-explorer
              formControlName="folder_source"
              [rootNodes]="[slashRootNode]"
              [readonly]="!hasRequiredRoles()"
              [label]="helptext.folderLabel | translate"
              [tooltip]="helptext.folderTooltip | translate"
              [multiple]="true"
              [nodeProvider]="bucketNodeProvider"
            ></ix-explorer>
          }
          @if (form.controls.bucket_policy_only.enabled) {
            <ix-checkbox
              formControlName="bucket_policy_only"
              [label]="helptext.bucketPolicyOnlyLabel | translate"
              [tooltip]="helptext.bucketPolicyOnlyTooltip | translate"
            ></ix-checkbox>
          }
        </ix-fieldset>

        <ix-fieldset
          class="fieldset"
          [title]="helptext.controlTitle | translate"
        >
          @if (form.controls.cloudsync_picker.enabled) {
            <ix-scheduler
              formControlName="cloudsync_picker"
              [required]="true"
              [label]="helptext.scheduleLabel | translate"
            ></ix-scheduler>
          }
          @if (form.controls.enabled.enabled) {
            <ix-checkbox
              formControlName="enabled"
              [label]="helptext.enabledLabel | translate"
            ></ix-checkbox>
          }
        </ix-fieldset>

        <ix-fieldset
          class="fieldset"
          [title]="helptext.advancedOptionsTitle | translate"
        >
          @if (googleDriveProviderIds.includes(form.controls.credentials.value)) {
            <ix-checkbox
              formControlName="acknowledge_abuse"
              [label]="helptext.acknowledgeAbuseLabel | translate"
              [tooltip]="helptext.acknowledgeAbuseTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.snapshot.enabled) {
            <ix-checkbox
              formControlName="snapshot"
              [label]="helptext.snapshotLabel | translate"
              [tooltip]="helptext.snapshotTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.create_empty_src_dirs.enabled) {
            <ix-checkbox
              formControlName="create_empty_src_dirs"
              [label]="helptext.emptySrcDirsLabel | translate"
            ></ix-checkbox>
          }
          @if (form.controls.follow_symlinks.enabled) {
            <ix-checkbox
              formControlName="follow_symlinks"
              [label]="helptext.followSymlinksLabel | translate"
              [tooltip]="helptext.followSymlinksTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.pre_script.enabled) {
            <ix-textarea
              formControlName="pre_script"
              [label]="helptext.preScriptLabel | translate"
              [tooltip]="helptext.preScriptTooltip | translate"
            ></ix-textarea>
          }
          @if (form.controls.post_script.enabled) {
            <ix-textarea
              formControlName="post_script"
              [label]="helptext.postScriptLabel | translate"
              [tooltip]="helptext.postScriptTooltip | translate"
            ></ix-textarea>
          }
          @if (form.controls.exclude.enabled) {
            <ix-chips
              formControlName="exclude"
              [label]="helptext.excludeLabel | translate"
              [tooltip]="helptext.excludeTooltip | translate"
            ></ix-chips>
          }
          @if (form.controls.task_encryption.enabled) {
            <ix-select
              formControlName="task_encryption"
              [label]="helptext.encryptionLabel | translate"
              [tooltip]="helptext.encryptionTooltip | translate"
              [options]="encryptionOptions$"
            ></ix-select>
          }
          <div class="advanced-title">
            {{ helptext.advancedRemoteOptionsTitle | translate }}
          </div>
          @if (form.controls.storage_class.enabled) {
            <ix-select
              formControlName="storage_class"
              [label]="helptext.storageClassLabel | translate"
              [tooltip]="helptext.storageClassTooltip | translate"
              [options]="storageClassOptions$"
            ></ix-select>
          }
          @if (form.controls.fast_list.enabled) {
            <ix-checkbox
              formControlName="fast_list"
              [label]="helptext.fastListLabel | translate"
              [tooltip]="helptext.fastListTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.encryption.enabled) {
            <ix-checkbox
              formControlName="encryption"
              [label]="helptext.remoteEncryptionLabel | translate"
              [tooltip]="helptext.remoteEncryptionTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.filename_encryption.enabled) {
            <ix-checkbox
              formControlName="filename_encryption"
              [label]="helptext.filenameEncryptionLabel | translate"
              [tooltip]="helptext.filenameEncryptionTooltip | translate"
            ></ix-checkbox>
          }
          @if (form.controls.encryption_password.enabled) {
            <ix-input
              formControlName="encryption_password"
              type="password"
              [label]="helptext.encryptionPasswordLabel | translate"
              [tooltip]="helptext.encryptionPasswordTooltip | translate"
            ></ix-input>
          }
          @if (form.controls.encryption_salt.enabled) {
            <ix-input
              formControlName="encryption_salt"
              type="password"
              [label]="helptext.encryptionSaltLabel | translate"
              [tooltip]="helptext.encryptionSaltTooltip | translate"
            ></ix-input>
          }
          @if (form.controls.transfers.enabled) {
            <ix-select
              formControlName="transfers"
              [options]="transfersOptions$"
              [label]="helptext.transfersLabel | translate"
              [tooltip]="helptext.transfersTooltip | translate"
            ></ix-select>
          }
          @if (form.controls.bwlimit.enabled) {
            <ix-chips
              formControlName="bwlimit"
              [label]="helptext.bwlimitLabel | translate"
              [tooltip]="helptext.bwlimitTooltip | translate"
            ></ix-chips>
          }
        </ix-fieldset>
      </div>

      <div class="form-actions">
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="submit"
          color="primary"
          ixTest="save"
          [disabled]="form.invalid || isLoading"
        >
          {{ 'Save' | translate }}
        </button>
        <button
          *ixRequiresRoles="requiredRoles"
          mat-button
          type="button"
          ixTest="dry-run"
          [disabled]="form.invalid || isLoading"
          (click)="onDryRun()"
        >
          {{ helptext.dryRunButton | translate }}
        </button>
        @if (isNew) {
          <button
            mat-button
            type="button"
            ixTest="switch-to-wizard"
            (click)="onSwitchToWizard()"
          >
            {{ 'Switch To Wizard' | translate }}
          </button>
        }
      </div>
    </form>
  </mat-card-content>
</mat-card>
